﻿using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using AdvancedGod.People.Couples;

namespace AdvancedGod.People
{
  /// <summary>
  /// Represents human
  /// </summary>
  public abstract class Human : IHasName
  {
    #region IHasName members
    /// <summary>
    /// Human's name
    /// </summary>
    public string Name { get; private set; }
    #endregion

    #region public properties
    /// <summary>
    /// Human's sex
    /// </summary>
    public Sex Sex { get; private set; }

    /// <summary>
    /// Human's age
    /// </summary>
    public int Age { get; set; }
    #endregion

    #region protected methods
    /// <summary>
    /// Constructs human
    /// </summary>
    /// <param name="sex">human's sex</param>
    /// <param name="name">human's name</param>
    protected Human(Sex sex, string name)
    {
      Sex = sex;
      Name = name;
      Age = 0;
    }

    /// <summary>
    /// Returns member info about concrete extended class
    /// </summary>
    /// <returns></returns>
    protected abstract MemberInfo GetMemberInfo();
    #endregion

    #region public methods
    /// <summary>
    /// Returns enumeration consists of couple attributes of this class type
    /// </summary>
    /// <returns>enumeration, contains all couple attributes of this class 
    /// type</returns>
    public IList<CoupleAttribute> GetAttributeEnumeration()
    {
      MemberInfo info = GetMemberInfo();
      object[] attributes =
        info.GetCustomAttributes(typeof(CoupleAttribute), false);
      return attributes.OfType<CoupleAttribute>().ToArray();
    }
    #endregion

  }

}
